package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    //查询列表
    @Override
    public PageResult<Activity> list(ActivityDto activityDto) {
        //设置Page Helpper分页参数
        PageHelper.startPage(activityDto.getPage(), activityDto.getPageSize());
        List<Activity> activityList = activityMapper.selectList(activityDto);
        Page<Activity>p=(Page<Activity>)activityList;
        return new PageResult<>(p.getTotal(),p.getResult());
    }
    //根据ID删除
    @Override
    public void deleteById(Integer id) {
        activityMapper.deleteById(id);
    }
    //添加活动
    @Override
    public void add(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.add(activity);
    }
    //根据ID查询
    @Override
    public Activity getByID(Integer id) {
        return activityMapper.selectByID(id);
    }
    //修改活动
    @Override
    public void upDate(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.upDate(activity);
    }
    //根据类型查询
    @Override
    public List<Activity> typeList(Integer type) {
        return activityMapper.typeList(type);

    }
}
